package cn.tedu.jdbc.Demo;

import cn.tedu.jdbc.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @author Justin Parker
 * @author 2024/8/1 下午10:41
 * @version 1.0
 */
public class DeleteDemo {
    public static void Delete(){
        try(Connection connection = DBUtil.getConnection()) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入用户id");
            String id = scanner.nextLine();


            String sql = "delete from userinfo where id = ? ";
            PreparedStatement ps = connection.prepareStatement(sql);

            ps.setString(1,id);
            int i = ps.executeUpdate();
            if (i>0){
                System.out.println("删除成功");
            }else {
                System.out.println("删除失败");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
